/***************************************************
// FileName: UVideoDevice.cpp
// ClassName: UVideoDevice
// Description: initialize and use MicroView card
// Author: MicroView
// Modify: xwt
// Date: 2007-7-1
****************************************************/

#include "StdAfx.h"
#include ".\uvideodevice.h"

UVideoDevice::UVideoDevice(void)
{
	m_CurDev			= NULL ;
	m_InitDeviceFlag	= FALSE ;
	m_StartGrabFlag		= FALSE ;
}

UVideoDevice::~UVideoDevice(void)
{
}

void UVideoDevice::InitVideoDevice()
{
	m_CurDev	=	MV_OpenDevice( 0, TRUE );
	if(m_CurDev)
	{
		m_InitDeviceFlag = TRUE ;
	}
}
void UVideoDevice::FiniVideoDevice()
{
	if(m_CurDev)
	{
		MV_CloseDevice(m_CurDev);
		m_CurDev			= NULL ;
		m_InitDeviceFlag	= FALSE ;
	}
}

void UVideoDevice::StartGrabDevice()
{
	if(m_CurDev && !m_StartGrabFlag)
	{
		MV_OperateDevice( m_CurDev, MVRUN );
		m_StartGrabFlag = TRUE ;
	}
}
void UVideoDevice::StopGrabDevice()
{
	if(m_CurDev && m_StartGrabFlag)
	{
		MV_OperateDevice( m_CurDev, MVSTOP );
		m_StartGrabFlag = FALSE ;
	}
}

void UVideoDevice::StartGrabOnDefault()
{
	if(m_CurDev && !m_StartGrabFlag)
	{
		SetGrabSize(DEFAULTWIDTH,DEFAULTHEIGHT);
#ifdef GRABMONO
		SetGrabBit(DATA_MONOCHOY8);
#else
		SetGrabBit(DATA_CO_RGB24);//DATA_aRGB8888);
#endif
		
		MV_OperateDevice( m_CurDev, MVRUN );
		m_StartGrabFlag = TRUE ;
	}
}

void UVideoDevice::GrabSingle(PVOID pImageBuf)
{
	if(m_CurDev && !m_StartGrabFlag)
	{		
		SetGrabSize(DEFAULTWIDTH,DEFAULTHEIGHT);
#ifdef GRABMONO
		SetGrabBit(DATA_MONOCHOY8);
#else
		SetGrabBit(DATA_CO_RGB24);//DATA_aRGB8888);
#endif

		MV_IMAGEINFO Info;
		MV_SetDeviceParameter(m_CurDev,SET_GARBIMAGEINFO,(DWORD)(&Info));
		
		PVOID pBuf = malloc(Info.Length);
		pImageBuf = MV_CaptureSingle(m_CurDev,FALSE,pBuf,Info.Length,&Info);

		free(pBuf);
	}
}
